//
//  JQImageView.m
//  SheShiDu
//
//  Created by 单剑秋 on 16/6/15.
//  Copyright © 2016年 单剑秋. All rights reserved.
//

#import "JQImageView.h"

@implementation JQImageView

+ (UIImage *)jq_captureCircleImage:(UIImage*)image
{
    CGFloat imageW = image.size.width;
    CGFloat imageH = image.size.height;
    imageW = imageW < imageH ? imageW : imageH;
    CGSize imageSize = CGSizeMake(imageW, imageH);
    
    // 边框
    CGFloat border = imageW / 100 * 6;
    CGFloat radius = imageSize.width * 0.5;
    
    CGSize graphicSize = CGSizeMake(imageSize.width + 2 * border, imageSize.height + 2 * border);
    UIGraphicsBeginImageContextWithOptions(graphicSize, NO, 0.0);
    
    //边框颜色
    [[UIColor colorWithRed:35 / 255.0 green:195 / 255.0 blue:183 / 255.0 alpha:1] setFill];
    CGContextRef context=UIGraphicsGetCurrentContext();
    CGContextAddArc(context,graphicSize.width * 0.5, graphicSize.height * 0.5, radius+border, -M_PI, M_PI, 0);
    CGContextFillPath(context);
    
    UIBezierPath *path= [UIBezierPath bezierPathWithArcCenter:CGPointMake(graphicSize.width * 0.5, graphicSize.height * 0.5) radius:radius startAngle:-M_PI endAngle:M_PI clockwise:YES];
    [path addClip];
    
    CGRect imageFrame= CGRectMake(border, border, imageSize.width , imageSize.height);
    [image drawInRect:imageFrame];
    UIImage *finishImage=UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return finishImage;
}

@end
